<html>
<head><meta charset="utf-8"><title>turn on const prop by default · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html">turn on const prop by default</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="180022465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022465">(Nov 06 2019 at 11:22)</a>:</h4>
<p>Hi <span class="user-mention" data-user-id="124288">@oli</span>, I hope you had a  good vacation!</p>
<p>Now that ConstProp is in a bit better state, I think we should consider turning it on by default (it's currently gated under <code>-Z mir-opt-level=2</code>). I did a perf run recently and the numbers looked pretty decent <a href="https://github.com/rust-lang/rust/pull/66074" target="_blank" title="https://github.com/rust-lang/rust/pull/66074">https://github.com/rust-lang/rust/pull/66074</a></p>
<p>What do you think? There's a few changes left (some I have locally and some yet to do) before I think ConstProp is "done" but perhaps it's time to start talking about running it by default.</p>



<a name="180022473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022473">(Nov 06 2019 at 11:22)</a>:</h4>
<p><span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span></p>



<a name="180022497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022497">(Nov 06 2019 at 11:23)</a>:</h4>
<p>I just did a double take</p>



<a name="180022514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022514">(Nov 06 2019 at 11:24)</a>:</h4>
<p>"pretty decent" is a very humble way to describe this</p>



<a name="180022547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022547">(Nov 06 2019 at 11:24)</a>:</h4>
<p>wow</p>



<a name="180022554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022554">(Nov 06 2019 at 11:24)</a>:</h4>
<p>The cte stress tests are major outliers but yeah the rest looks good IMO</p>



<a name="180022556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022556">(Nov 06 2019 at 11:24)</a>:</h4>
<p><span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="180022590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022590">(Nov 06 2019 at 11:25)</a>:</h4>
<p>yea we should totally turn them on if optimizations are enabled. Though not in debug mode. I'm not sure how much mir optimizations and llvm optimizations are entangled</p>



<a name="180022662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022662">(Nov 06 2019 at 11:26)</a>:</h4>
<p>Is your concern mangling debuginfo?</p>



<a name="180022717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022717">(Nov 06 2019 at 11:27)</a>:</h4>
<p>(Debug perf.rlo results also show improvement so I'd love to get those compile time improvements as well)</p>



<a name="180022719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022719">(Nov 06 2019 at 11:27)</a>:</h4>
<p>partially, but I also don't think we're running any opportunistic optimizations in debug mode right now</p>



<a name="180022723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022723">(Nov 06 2019 at 11:27)</a>:</h4>
<p>hmm that's true though</p>



<a name="180022725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022725">(Nov 06 2019 at 11:27)</a>:</h4>
<p>Yeah</p>



<a name="180022779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022779">(Nov 06 2019 at 11:28)</a>:</h4>
<p>I think ConstProp is relatively safe in terms of the debugging experience because we don't (currently anyway) propagate away function calls</p>



<a name="180022781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022781">(Nov 06 2019 at 11:28)</a>:</h4>
<p>I could create a compiler team FCP for it</p>



<a name="180022796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022796">(Nov 06 2019 at 11:29)</a>:</h4>
<p>also we just prop temporaries</p>



<a name="180022817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022817">(Nov 06 2019 at 11:29)</a>:</h4>
<p>so user code is not affected very much</p>



<a name="180022818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022818">(Nov 06 2019 at 11:29)</a>:</h4>
<p>So beyond looking at the disassembly, the user shouldn't really be able to tell if, for example, <code>let x = 2 + 2</code> is happening at runtime or compile time.</p>



<a name="180022839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022839">(Nov 06 2019 at 11:29)</a>:</h4>
<p>jup</p>



<a name="180022840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022840">(Nov 06 2019 at 11:29)</a>:</h4>
<p>We could do either of those yeah</p>



<a name="180022855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022855">(Nov 06 2019 at 11:30)</a>:</h4>
<p>why did you choose to not prop pointers?</p>



<a name="180022899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180022899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180022899">(Nov 06 2019 at 11:30)</a>:</h4>
<p>heh</p>



<a name="180023005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023005">(Nov 06 2019 at 11:32)</a>:</h4>
<p>So when I introduced <code>ConstPropMachine</code>, we lost the code that handles interning <code>Memory</code>. It happens to work ok for the <code>mir-opt</code> tests, probably because the tests are small and compilation is deterministic enough to end up with <code>AllocId</code>s from <code>ConstPropMachine</code> matching up exactly with the same ones from <code>CompileTimeInterpreter</code>. However, if I just switch on const prop without that check in <code>should_const_prop</code>, the bootstrap will ICE when compiling <code>core</code>.</p>



<a name="180023013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023013">(Nov 06 2019 at 11:32)</a>:</h4>
<p>So I added that code to skip pointers to avoid the ICE</p>



<a name="180023174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023174">(Nov 06 2019 at 11:35)</a>:</h4>
<p>oh, interesting. This could probably be resolved by interning all such constants before throwing away the <code>InterpCx</code></p>



<a name="180023182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023182">(Nov 06 2019 at 11:35)</a>:</h4>
<p>orthogonal though</p>



<a name="180023215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023215">(Nov 06 2019 at 11:36)</a>:</h4>
<p>ok, let's go with integer-only const prop enabled even in debug mode for now and see how the rest of T-compiler likes it</p>



<a name="180023262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023262">(Nov 06 2019 at 11:36)</a>:</h4>
<p>can you leave a comment explaining the no-pointer-strategy in the source code?</p>



<a name="180023279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023279">(Nov 06 2019 at 11:36)</a>:</h4>
<p>Sure, yeah. That was just a throw-away commit to get the perf results.</p>



<a name="180023309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023309">(Nov 06 2019 at 11:37)</a>:</h4>
<p>How does compiler team FCP work? Is that something we trigger on the PR?</p>



<a name="180023483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023483">(Nov 06 2019 at 11:40)</a>:</h4>
<p>yea</p>



<a name="180023499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023499">(Nov 06 2019 at 11:40)</a>:</h4>
<p>Ok, I'm adding some comments to that commit now and I'll push in a minute.</p>



<a name="180023506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023506">(Nov 06 2019 at 11:40)</a>:</h4>
<p>Are you concerned about the slight regression in the codegen tests?</p>



<a name="180023530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180023530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180023530">(Nov 06 2019 at 11:41)</a>:</h4>
<p>I have some local changes that actually improve those to the point NO-OPT is equivalent to the other optimized cases.</p>



<a name="180024134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180024134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180024134">(Nov 06 2019 at 11:51)</a>:</h4>
<p>huh, why did no-opt optimize to <code>8</code> before this PR anyway?</p>



<a name="180024242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180024242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180024242">(Nov 06 2019 at 11:53)</a>:</h4>
<p>It only did in the test for <code>inline(always)</code></p>



<a name="180024251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180024251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180024251">(Nov 06 2019 at 11:53)</a>:</h4>
<p>I think it's an artifact related to inlining an optimized function</p>



<a name="180024737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180024737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180024737">(Nov 06 2019 at 12:00)</a>:</h4>
<p>oh lol, llvm already const props in debug mode, you're right</p>



<a name="180024740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180024740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180024740">(Nov 06 2019 at 12:00)</a>:</h4>
<p>the inlining does the trick</p>



<a name="180024751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180024751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180024751">(Nov 06 2019 at 12:00)</a>:</h4>
<p>ok, so there's no reason not do do const prop in debug mode</p>



<a name="180024761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180024761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180024761">(Nov 06 2019 at 12:01)</a>:</h4>
<p>llvm does it, so we should, too</p>



<a name="180025107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180025107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180025107">(Nov 06 2019 at 12:05)</a>:</h4>
<p>Yeah, I think this change is also ok <a href="https://github.com/rust-lang/rust/pull/66074/files#diff-d3d378e46f2b79fa680365c64848f456R34" target="_blank" title="https://github.com/rust-lang/rust/pull/66074/files#diff-d3d378e46f2b79fa680365c64848f456R34">https://github.com/rust-lang/rust/pull/66074/files#diff-d3d378e46f2b79fa680365c64848f456R34</a></p>



<a name="180025109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180025109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180025109">(Nov 06 2019 at 12:05)</a>:</h4>
<p>lmk if you think otherwise</p>



<a name="180025196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180025196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180025196">(Nov 06 2019 at 12:06)</a>:</h4>
<p>I have a few commits locally that improve const prop and the simplify locals pass a bit more and actually get us to </p>
<div class="codehilite"><pre><span></span>// NO-OPT: ret i32 8
</pre></div>


<p>on these tests</p>



<a name="180026345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180026345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180026345">(Nov 06 2019 at 12:25)</a>:</h4>
<p>cool, we could merge that independently. About the <code>%0.1</code> -&gt; <code>%3</code> changes, I can't figure out how the <code>%3</code> actually happens, can you dump the entire llvm IR?</p>



<a name="180026380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180026380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180026380">(Nov 06 2019 at 12:25)</a>:</h4>
<p>I don't think the change is problematic, I just don't get what happened</p>



<a name="180032998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180032998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180032998">(Nov 06 2019 at 13:43)</a>:</h4>
<p>Before:</p>
<div class="codehilite"><pre><span></span><span class="c">; Function Attrs: nonlazybind uwtable</span>
<span class="k">define</span> <span class="k">i32</span> <span class="vg">@nothing</span><span class="p">()</span> <span class="k">unnamed_addr</span> <span class="vg">#0</span> <span class="p">{</span>
<span class="nl">start:</span>
  <span class="nv nv-Anonymous">%0</span> <span class="p">=</span> <span class="k">call</span> <span class="p">{</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i1</span> <span class="p">}</span> <span class="vg">@llvm.sadd.with.overflow.i32</span><span class="p">(</span><span class="k">i32</span> <span class="m">2</span><span class="p">,</span> <span class="k">i32</span> <span class="m">2</span><span class="p">)</span>
  <span class="nv">%_1.0</span> <span class="p">=</span> <span class="k">extractvalue</span> <span class="p">{</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i1</span> <span class="p">}</span> <span class="nv nv-Anonymous">%0</span><span class="p">,</span> <span class="m">0</span>
  <span class="nv">%_1.1</span> <span class="p">=</span> <span class="k">extractvalue</span> <span class="p">{</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i1</span> <span class="p">}</span> <span class="nv nv-Anonymous">%0</span><span class="p">,</span> <span class="m">1</span>
  <span class="nv nv-Anonymous">%1</span> <span class="p">=</span> <span class="k">call</span> <span class="k">i1</span> <span class="vg">@llvm.expect.i1</span><span class="p">(</span><span class="k">i1</span> <span class="nv">%_1.1</span><span class="p">,</span> <span class="k">i1</span> <span class="k">false</span><span class="p">)</span>
  <span class="k">br</span> <span class="k">i1</span> <span class="nv nv-Anonymous">%1</span><span class="p">,</span> <span class="k">label</span> <span class="nv">%panic</span><span class="p">,</span> <span class="k">label</span> <span class="nv">%bb1</span>

<span class="nl">bb1:</span>                                              <span class="c">; preds = %start</span>
  <span class="k">ret</span> <span class="k">i32</span> <span class="nv">%_1.0</span>

<span class="nl">panic:</span>                                            <span class="c">; preds = %start</span>
<span class="c">; call core::panicking::panic</span>
  <span class="k">call</span> <span class="k">void</span> <span class="vg">@_ZN4core9panicking5panic17h7eae3940edceae86E</span><span class="p">([</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]*</span> <span class="k">noalias</span> <span class="k">nonnull</span> <span class="k">readonly</span> <span class="k">align</span> <span class="m">1</span> <span class="k">bitcast</span> <span class="p">([</span><span class="m">28</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]*</span> <span class="vg">@str.0</span> <span class="k">to</span> <span class="p">[</span><span class="m">0</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]*),</span> <span class="k">i64</span> <span class="m">28</span><span class="p">,</span> <span class="nv">%&quot;core::panic::Location&quot;</span><span class="p">*</span> <span class="k">noalias</span> <span class="k">readonly</span> <span class="k">align</span> <span class="m">8</span> <span class="k">dereferenceable</span><span class="p">(</span><span class="m">24</span><span class="p">)</span> <span class="k">bitcast</span> <span class="p">(&lt;{</span> <span class="k">i8</span><span class="p">*,</span> <span class="p">[</span><span class="m">16</span> <span class="k">x</span> <span class="k">i8</span><span class="p">]</span> <span class="p">}&gt;*</span> <span class="vg">@1</span> <span class="k">to</span> <span class="nv">%&quot;core::panic::Location&quot;</span><span class="p">*))</span>
  <span class="k">unreachable</span>
<span class="p">}</span>
</pre></div>


<p>After:</p>
<div class="codehilite"><pre><span></span><span class="k">define</span> <span class="k">i32</span> <span class="vg">@nothing</span><span class="p">()</span> <span class="k">unnamed_addr</span> <span class="vg">#0</span> <span class="p">{</span>
<span class="nl">start:</span>
  <span class="nv">%_1</span> <span class="p">=</span> <span class="k">alloca</span> <span class="p">{</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i8</span> <span class="p">},</span> <span class="k">align</span> <span class="m">4</span>
  <span class="nv nv-Anonymous">%0</span> <span class="p">=</span> <span class="k">bitcast</span> <span class="p">{</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i8</span> <span class="p">}*</span> <span class="nv">%_1</span> <span class="k">to</span> <span class="k">i32</span><span class="p">*</span>
  <span class="k">store</span> <span class="k">i32</span> <span class="m">4</span><span class="p">,</span> <span class="k">i32</span><span class="p">*</span> <span class="nv nv-Anonymous">%0</span><span class="p">,</span> <span class="k">align</span> <span class="m">4</span>
  <span class="nv nv-Anonymous">%1</span> <span class="p">=</span> <span class="k">getelementptr</span> <span class="k">inbounds</span> <span class="p">{</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i8</span> <span class="p">},</span> <span class="p">{</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i8</span> <span class="p">}*</span> <span class="nv">%_1</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">1</span>
  <span class="k">store</span> <span class="k">i8</span> <span class="m">0</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv nv-Anonymous">%1</span><span class="p">,</span> <span class="k">align</span> <span class="m">4</span>
  <span class="nv nv-Anonymous">%2</span> <span class="p">=</span> <span class="k">bitcast</span> <span class="p">{</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i8</span> <span class="p">}*</span> <span class="nv">%_1</span> <span class="k">to</span> <span class="k">i32</span><span class="p">*</span>
  <span class="nv nv-Anonymous">%3</span> <span class="p">=</span> <span class="k">load</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i32</span><span class="p">*</span> <span class="nv nv-Anonymous">%2</span><span class="p">,</span> <span class="k">align</span> <span class="m">4</span>
  <span class="k">ret</span> <span class="k">i32</span> <span class="nv nv-Anonymous">%3</span>
<span class="p">}</span>
</pre></div>



<a name="180033512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180033512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180033512">(Nov 06 2019 at 13:48)</a>:</h4>
<p>that seems like a pessimization :D</p>



<a name="180033687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180033687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180033687">(Nov 06 2019 at 13:50)</a>:</h4>
<p>oooh, I think I know what's going on. The <code>ConstValue::ByRef</code> of the tuple is not converted to an llvm tuple</p>



<a name="180033717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180033717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180033717">(Nov 06 2019 at 13:51)</a>:</h4>
<p>this seems like an easy fix in codegen that should improve all uses of such constants</p>



<a name="180035508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180035508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180035508">(Nov 06 2019 at 14:10)</a>:</h4>
<p>I don't really understand the cost model for LLVM instructions so I can't say. My thought was that before we actually did the add with overflow and branched on the result where as now we just put the correct values into variables and return the result from a variable load so it was probably faster?</p>



<a name="180036854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180036854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180036854">(Nov 06 2019 at 14:26)</a>:</h4>
<p>well. it's probably still cheaper than it was before, but the initial code we generate is a bit odd</p>



<a name="180036870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180036870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180036870">(Nov 06 2019 at 14:27)</a>:</h4>
<p>it computes pointers into the constant allocation and reads the tuple values out of it</p>



<a name="180036893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180036893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180036893">(Nov 06 2019 at 14:27)</a>:</h4>
<p>but llvm can work without an allocation by just creating a const tuple</p>



<a name="180036898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180036898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180036898">(Nov 06 2019 at 14:27)</a>:</h4>
<p>not sure what is better</p>



<a name="180036926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180036926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180036926">(Nov 06 2019 at 14:27)</a>:</h4>
<p>seems fine either way for the PR, but we should probably look into it</p>



<a name="180037170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180037170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180037170">(Nov 06 2019 at 14:29)</a>:</h4>
<blockquote>
<p>oli: oooh, I think I know what's going on. The ConstValue::ByRef of the tuple is not converted to an llvm tuple</p>
<p>oli: this seems like an easy fix in codegen that should improve all uses of such constants</p>
</blockquote>
<p>I've been wanting to learn more about LLVM so this sounds like an interesting project to me. Hopefully not too large? Do you think this would be something a newbie to LLVM could tackle?</p>



<a name="180037346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180037346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180037346">(Nov 06 2019 at 14:31)</a>:</h4>
<p>I need to check to be sure but I think some changes I have laying around my machine will change this to </p>
<div class="codehilite"><pre><span></span><span class="k">define</span> <span class="k">i32</span> <span class="vg">@nothing</span><span class="p">()</span> <span class="k">unnamed_addr</span> <span class="vg">#0</span> <span class="p">{</span>
<span class="nl">start:</span>
  <span class="k">ret</span> <span class="k">i32</span> <span class="m">8</span>
<span class="p">}</span>
</pre></div>


<p>but I will need to retest to be certain. </p>
<p>The main change is to allocate space for the MIR return value and allow propagating into that.</p>



<a name="180041328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180041328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180041328">(Nov 06 2019 at 15:10)</a>:</h4>
<blockquote>
<p>I've been wanting to learn more about LLVM so this sounds like an interesting project to me. Hopefully not too large? Do you think this would be something a newbie to LLVM could tackle?</p>
</blockquote>
<p>Yea this should be very self-contained. But I'm not sure that doing it is useless complexity considering that llvm optimizations will clean it up nicely</p>



<a name="180041363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180041363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180041363">(Nov 06 2019 at 15:11)</a>:</h4>
<p>we may be able to get rid of it by doing the field reading in const prop, too, so that may be simpler</p>



<a name="180042032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180042032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180042032">(Nov 06 2019 at 15:18)</a>:</h4>
<p>Ok, I'll work on upstreaming my other const prop changes first and we can see if it's still necessary after that.</p>



<a name="180044472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180044472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180044472">(Nov 06 2019 at 15:41)</a>:</h4>
<blockquote>
<p>Is your concern mangling debuginfo?</p>
</blockquote>
<p>well we know debuginfo is broken for opt-level=2... <a href="https://github.com/rust-lang/rust/issues/66077" target="_blank" title="https://github.com/rust-lang/rust/issues/66077">https://github.com/rust-lang/rust/issues/66077</a></p>



<a name="180044664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180044664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180044664">(Nov 06 2019 at 15:42)</a>:</h4>
<blockquote>
<p>So I added that code to skip pointers to avoid the ICE</p>
</blockquote>
<p>(about pointers)<br>
so, uh, how reliable is that? contsprop results should obviously not be interned so I am not sure how that's related...<br>
I guess I am asking, where is the ICE originating?</p>



<a name="180044746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180044746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180044746">(Nov 06 2019 at 15:43)</a>:</h4>
<blockquote>
<p>contsprop results should obviously not be interned</p>
</blockquote>
<p>that's not obvious to me</p>



<a name="180044871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180044871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180044871">(Nov 06 2019 at 15:44)</a>:</h4>
<p>if we have <code>Foo { a: 42, b: 99, c: 52 }</code> and we turn it into a single constant, why not intern its allocation?</p>



<a name="180044921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180044921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180044921">(Nov 06 2019 at 15:45)</a>:</h4>
<p>I was thinking of temporary intermediate computations... hm</p>



<a name="180045969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180045969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180045969">(Nov 06 2019 at 15:55)</a>:</h4>
<blockquote>
<blockquote>
<p>Is your concern mangling debuginfo?</p>
</blockquote>
<p>well we know debuginfo is broken for opt-level=2... <a href="https://github.com/rust-lang/rust/issues/66077" target="_blank" title="https://github.com/rust-lang/rust/issues/66077">https://github.com/rust-lang/rust/issues/66077</a></p>
</blockquote>
<p>That's related to the MIR Inline pass which is still gated under <code>-Z mir-opt-level=2</code> so I don't think it's really relevant to const prop. </p>
<blockquote>
<p>so, uh, how reliable is that?</p>
</blockquote>
<p>Should be totally reliable I believe unless I'm missing something <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span> </p>
<p><a href="https://github.com/rust-lang/rust/pull/66074/files#diff-9e103702275cbef342c2decd3395bf3bR627-R634" target="_blank" title="https://github.com/rust-lang/rust/pull/66074/files#diff-9e103702275cbef342c2decd3395bf3bR627-R634">https://github.com/rust-lang/rust/pull/66074/files#diff-9e103702275cbef342c2decd3395bf3bR627-R634</a></p>



<a name="180220913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180220913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180220913">(Nov 08 2019 at 11:22)</a>:</h4>
<blockquote>
<p>Ok, I'll work on upstreaming my other const prop changes first and we can see if it's still necessary after that.</p>
</blockquote>
<p>Looks like LLVM changes won't be necessary. With <a href="https://github.com/rust-lang/rust/issues/66216" target="_blank" title="https://github.com/rust-lang/rust/issues/66216">#66216</a>, here's the LLVM ir that's generated:</p>
<div class="codehilite"><pre><span></span><span class="k">define</span> <span class="k">i32</span> <span class="vg">@nothing</span><span class="p">()</span> <span class="k">unnamed_addr</span> <span class="vg">#0</span> <span class="p">{</span>
<span class="nl">start:</span>
  <span class="k">ret</span> <span class="k">i32</span> <span class="m">4</span>
<span class="p">}</span>
</pre></div>


<p><span aria-label="smiley" class="emoji emoji-1f603" role="img" title="smiley">:smiley:</span></p>



<a name="180220926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180220926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180220926">(Nov 08 2019 at 11:22)</a>:</h4>
<p>In debug, no optimization mode <span aria-label="tada" class="emoji emoji-1f389" role="img" title="tada">:tada:</span></p>



<a name="180220956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180220956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180220956">(Nov 08 2019 at 11:23)</a>:</h4>
<p>sweet</p>



<a name="180431838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180431838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180431838">(Nov 11 2019 at 15:21)</a>:</h4>
<p>Looks like most of the compiler team has <a href="https://github.com/rust-lang/rust/pull/66074#issuecomment-550274874" target="_blank" title="https://github.com/rust-lang/rust/pull/66074#issuecomment-550274874">signed off</a> on turning on const prop by default. I don't know what the standard procedure for polls is. Should we wait until everyone signs off before merging?</p>



<a name="180443841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180443841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180443841">(Nov 11 2019 at 17:43)</a>:</h4>
<p>I think everyone but two is needed</p>



<a name="180443987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180443987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180443987">(Nov 11 2019 at 17:45)</a>:</h4>
<p>I suppose we're technically there but niko forgot to check his box off.</p>



<a name="180444043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180444043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180444043">(Nov 11 2019 at 17:46)</a>:</h4>
<p>(I'm assuming that's what <code>@rfcbot reviewed</code> means)</p>



<a name="180445651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180445651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180445651">(Nov 11 2019 at 18:07)</a>:</h4>
<p>jop</p>



<a name="180445664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180445664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180445664">(Nov 11 2019 at 18:07)</a>:</h4>
<p>I checked niko's box</p>



<a name="180445667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180445667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180445667">(Nov 11 2019 at 18:07)</a>:</h4>
<p>so</p>



<a name="180445836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/turn%20on%20const%20prop%20by%20default/near/180445836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/turn.20on.20const.20prop.20by.20default.html#180445836">(Nov 11 2019 at 18:09)</a>:</h4>
<p>I will rebase this tonight then and update the tests to reflect the final state so you can review.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>